package org.lanqiao.api.order;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.OrderListPOJO;
import org.lanqiao.service.OrderServiceImpl;
import org.lanqiao.util.StringUtil;


/**
 * 添加订单接口
 */
@WebServlet("/api/order/AddOrderServlet")
public class AddOrderServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		/**
		 * 获取参数
		 */
			String userId=request.getParameter("orderUserId");
			String total=request.getParameter("orderTotalPrice");
			String comment=request.getParameter("orderComment");
			System.out.println(request.getParameter("carId"));
			ArrayList<String> str=StringUtil.getArray(request.getParameter("carId"));
			System.out.println("car:"+str.toString());
			OrderListPOJO order=new OrderListPOJO();
			order.setUserId(userId);
			order.setTotalPrice(total);
			order.setComment(comment);
			/**
			 * 调用添加订单
			 */
			OrderServiceImpl abc=new OrderServiceImpl();
			JsonResult result=null;
			try {
				List list=abc.addOrder(order,str);
				if(list!=null&list.size()>0){
					result=new JsonResult("添加成功",Constants.STATUS_SUCCESS,list);
				}else {
					result=new JsonResult("添加错误",Constants.STATUS_UNFOUND);
				}
			} catch (Exception e) {
				result=new JsonResult("添加异常",Constants.STATUS_FAILURE);
			}
			JsonResultWriter.writer(response, result);;
	}

}
